package com.person.leetcode.editor.cn;

/**
  * 121.买卖股票的最佳时机
  * 2022-07-14 18:01:21
**/
public class Sequence_0121_BestTimeToBuyAndSellStock {
    public static void main(String[] args) {
        Solution solution = new Sequence_0121_BestTimeToBuyAndSellStock().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int maxProfit(int[] p) {
        int min = Integer.MAX_VALUE;
        int max = 0;
        for (int i = 0; i < p.length; i++) {
            if (p[i]<min){
                min = p[i];
            }else{
                if (p[i] - min > max){
                    max = p[i] - min;
                }
            }
        }
        return max;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}